<template>
  <el-form size="default" :model="ruleForm" :rules="rules" ref="rule" label-width="100px" class="demo-ruleForm">
    <el-tabs v-model="activeName" tab-position="left">
      <el-tab-pane label="比赛设置" name="first">
        <el-form-item label="比赛名" prop="name">
          <div class="el-input">
            <el-input v-model="ruleForm.name"></el-input>
          </div>
        </el-form-item>
        <el-form-item label="选择团队">
          <el-select v-model="ruleForm.teamid" placeholder="请选择搜索团队" filterable :remote-method="remoteMethod1"
            :loading="loading" remote clearable reserve-keyword>
            <el-option v-for="item in getteam" :key="item.ID" :label="item.name" :value="Number(item.ID)"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="比赛类型" prop="type">
          <el-radio-group v-model="ruleForm.type">
            <el-radio label="public">公开比赛</el-radio>
            <el-radio label="limit">私有比赛</el-radio>
          </el-radio-group>
          &nbsp;
          &nbsp;
          &nbsp;
          <small class="text-black-50">不能参加该比赛的用户是否在比赛界面显示该比赛</small>
        </el-form-item>
        <el-form-item v-if="ruleForm.type === 'limit'" label="选择人员">
          <el-input placeholder="请输入内容" :modelValue="users" disabled class="input-with-select">
            <template #append>
              <el-button @click="dialogVisible2 = true">选择用户</el-button>
            </template>
          </el-input>

          <el-dialog title="请选择用户" v-model="dialogVisible2" width="900px" close-on-click-modal close-on-press-escape>
            <User :tablekey="['name', 'headportrait']" :handleSelectionChange="handleSelectionChange"
              :selectarr="selectarr">
            </User>
            <template #footer>
              <span class="dialog-footer">
                <el-button @click="dialogVisible2 = false">关闭</el-button>
              </span>
            </template>
          </el-dialog>
        </el-form-item>
        <el-form-item label="未指定人员">
          <el-radio-group v-model="ruleForm.usershow">
            <el-radio :label="false">在比赛列表显示</el-radio>
            <el-radio :label="true">在比赛列表不显示</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="未登录是否显示" label-width="130px">
          <el-radio-group v-model="ruleForm.isshow">
            <el-radio :label="false">显示</el-radio>
            <el-radio :label="true">不显示</el-radio>
          </el-radio-group>
          &nbsp;
          &nbsp;
          &nbsp;
          <small class="text-black-50">未登录的用户是否在比赛界面显示该比赛</small>

        </el-form-item>
        <el-form-item label="关联题单" v-show="!route.query.ID">
          <div class="row">
            <div class="col">
              <el-select v-model="matchquestionbankid" placeholder="请选择搜索题单" filterable :remote-method="remoteMethod"
                :loading="loading" remote reserve-keyword>
                <el-option v-for="item in getquestionbank" :key="item.ID" :label="item.name" :value="Number(item.ID)">
                </el-option>
              </el-select>
            </div>
          </div>
        </el-form-item>
        <el-form-item label="默认语言">
          <el-select v-model="ruleForm.language" placeholder="请选择">
            <el-option label="C" value="C">C</el-option>
            <el-option label="C++" value="C++">C++</el-option>
            <el-option label="Python" value="Python">Python</el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="报名时间" v-if="ruleForm.type !== 'limit'">
          <el-date-picker v-model="signUp" type="datetimerange" range-separator="至" start-placeholder="开始日期"
            end-placeholder="结束日期"></el-date-picker>
        </el-form-item>
        <el-form-item label="比赛时间" prop="signupstarttime">
          <el-date-picker v-model="startTime" type="datetimerange" range-separator="至" start-placeholder="开始日期"
            end-placeholder="结束日期"></el-date-picker>
        </el-form-item>
        <el-form-item label="比赛模式">
          <el-radio-group v-model="duration">
            <el-tooltip class="box-item" effect="dark"
              content="参赛时间以参赛者个人首次进入比赛时间为准，持续若干分钟。参赛者在比赛时间内均可进入，当比赛时间结束或持续时长倒计时结束时需提交此次比赛试卷" placement="top">
              <el-radio :label="false">全员统一计时</el-radio>
            </el-tooltip>
            <el-tooltip class="box-item" effect="dark" content="参赛时间以比赛开始、结束时间为准" placement="top">
              <el-radio :label="true">个人单独计时</el-radio>
            </el-tooltip>
          </el-radio-group>
        </el-form-item>
        <el-form-item v-show="duration" label="答题时间(分钟)" label-width="130px">
          <el-input-number :step="5" :min="1" :max="1200" step-strictly v-model="ruleForm.duration"></el-input-number>
        </el-form-item>
        <el-form-item label="比赛积分">
          <el-input-number :step="1" :min="1" :max="100" step-strictly v-model="ruleForm.integral"></el-input-number>
        </el-form-item>
        <el-form-item label="未报名是否展示比赛说明">
          <el-radio-group v-model="ruleForm.isinvitation">
            <el-radio :label="true">不展示</el-radio>
            <el-radio :label="false">展示</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="比赛激活码">
          <el-tooltip class="box-item" effect="dark" content="填写次选项，参赛者需要通过输入比赛激活码验证，如果多个激活码请用英文逗号分开" placement="top">
            <el-input placeholder="可以设置比赛激活码，对于需要报名的比赛，需要激活码才可以报名" :step="1" :min="4" :max="4" step-strictly
              v-model="ruleForm.invitation"></el-input>
          </el-tooltip>
        </el-form-item>
        <el-form-item label="比赛说明" prop="context">
          <Wangeditor id="context" :value="context" ref="contexteditor" :zIndex="2" :context="htmlcontext"></Wangeditor>
        </el-form-item>
        <el-form-item label="试卷结果展示">
          <el-radio-group v-model="ruleForm.result">
            <el-radio :label="0">交卷展示得分</el-radio>
            <el-radio :label="1">交卷展示对错题</el-radio>
            <el-radio :label="2">交卷展示题目解析</el-radio>
            <el-radio :label="3">不展示结果</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="是否展示排行">
          <el-radio-group v-model="ruleForm.isranking">
            <el-radio :label="true">展示</el-radio>
            <el-radio :label="false">不展示</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="是否展示查重">
          <el-radio-group v-model="ruleForm.isduplicate">
            <el-radio :label="false">展示</el-radio>
            <el-radio :label="true">不展示</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="是否展示题目名称" label-width="130px">
          <el-radio-group v-model="ruleForm.isshowquestionname">
            <el-radio :label="true">展示</el-radio>
            <el-radio :label="false">不展示</el-radio>
          </el-radio-group>
        </el-form-item>
        <!-- <el-form-item label="通知发送">
          <el-radio-group v-model="ruleForm.isnotice">
            <el-radio :label="true">展示</el-radio>
            <el-radio :label="false">不展示</el-radio>
          </el-radio-group>
        </el-form-item>-->
        <el-form-item label="是否增加报名后展示内容" label-width="130px">
          <el-radio-group v-model="ruleForm.isapplication">
            <el-radio :label="true">展示</el-radio>
            <el-radio :label="false">不展示</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="是否增加报名后展示内容" label-width="130px">
          <Wangeditor id="Wangeditor" :value="applicationcontext" ref="contexteditor2" :zIndex="2"
            :context="htmlapplicationcontext">
          </Wangeditor>
        </el-form-item>
        <div class="row">
          <div class="col text-right">
            <el-button @click="$router.go(-1)">取消</el-button>
            <el-button type="success" @click="submit(false, true)">下一步</el-button>
            <el-button v-show="false" type="success" @click="submit(false, true)">保存</el-button>
          </div>
        </div>
      </el-tab-pane>
      <el-tab-pane label="比赛题目设置" name="two" :disabled="Boolean(!ruleForm.ID)">
        <questionbankinput :select="selectquestion"></questionbankinput>
        <div class="row">
          <div class="col">
            <el-badge :value="questions.filter((e) => e.type === '代码').length" class="item">
              <el-popover placement="top">
                <el-button type="danger" @click="clearquestion('代码')">清空</el-button>
                <template #reference>
                  <el-button size="default">代码</el-button>
                </template>
              </el-popover>
            </el-badge>
            <el-badge :value="questions.filter((e) => e.type === '单选').length" class="item">
              <el-popover placement="top">
                <el-button type="danger" @click="clearquestion('单选')">清空</el-button>
                <template #reference>
                  <el-button class="ml-3" size="default">单选</el-button>
                </template>
              </el-popover>
            </el-badge>
            <el-badge :value="questions.filter((e) => e.type === '多选').length" class="item">
              <el-popover placement="top">
                <el-button type="danger" @click="clearquestion('多选')">清空</el-button>
                <template #reference>
                  <el-button class="ml-3" size="default">多选</el-button>
                </template>
              </el-popover>
            </el-badge>
            <el-badge :value="questions.filter((e) => e.type === '判断').length" class="item">
              <el-popover placement="top">
                <el-button size="default" type="danger" @click="clearquestion('判断')">清空</el-button>
                <template #reference>
                  <el-button class="ml-3" size="default">判断</el-button>
                </template>
              </el-popover>
            </el-badge>
            <el-badge :value="questions.filter((e) => e.type === '填空').length" class="item">
              <el-popover placement="top">
                <el-button size="default" type="danger" @click="clearquestion('填空')">清空</el-button>
                <template #reference>
                  <el-button class="ml-3" size="default">填空</el-button>
                </template>
              </el-popover>
            </el-badge>
          </div>

          <div class="col">
            <el-form-item label="设置分数">
              <el-input placeholder="请输入内容" v-model.number="input3" class="input-with-select">
                <template #prepend>
                  <el-select v-model="select" placeholder="请选择">
                    <el-option label="代码" value="代码"></el-option>
                    <el-option label="单选" value="单选"></el-option>
                    <el-option label="多选" value="多选"></el-option>
                    <el-option label="判断" value="判断"></el-option>
                    <el-option label="填空" value="填空"></el-option>
                  </el-select>
                </template>
                <template #append>
                  <el-button @click="change(input3, select)">设置</el-button>
                </template>
              </el-input>
            </el-form-item>
          </div>
        </div>
        <el-form-item label="拖拽调整排序"></el-form-item>
        <table class="table table-bordered">
          <thead>
            <tr>
              <td>名称</td>
              <td class="text-center">类型</td>
              <td class="text-center">分值</td>
              <td class="text-center">操作</td>
            </tr>
          </thead>
          <vuedraggable tag="tbody" v-model="questions" item-key="ID">
            <template #item="{ element, index }">
              <tr>
                <td>{{ element.name }}</td>
                <td class="text-center">
                  <el-tag>{{ element.type }}</el-tag>
                </td>
                <td class="text-center">
                  <el-input placeholder="请输入分值" v-model.number="element.score" style="width: 100px"></el-input>
                </td>
                <td class="text-center">
                  <el-button type="danger" circle @click="delquestion(index)">
                    <el-icon>
                      <Close />
                    </el-icon>
                  </el-button>
                </td>
              </tr>
            </template>
          </vuedraggable>
        </table>
        <div class="row">
          <div class="col text-right">
            <el-button @click="activeName = 'first'">上一步</el-button>
            <el-button type="success" @click="submit(true)">保存</el-button>
          </div>
        </div>
      </el-tab-pane>
    </el-tabs>
    <el-dialog title="比赛建议" v-model="dialogVisible3" width="900px" close-on-click-modal close-on-press-escape>
      <ol>
        <li v-show="jctest.a1.length">
          <h5>测试点数建议&gt;5</h5>
          <ul>
            <li v-for="(v, k) in jctest.a1">第{{ v[0] + 1 }}题只有{{ v[1] }}个测试点，数量较少</li>
          </ul>
        </li>
        <li v-show="jctest.a2.length">
          <h5>测试点数建议 &lt;50</h5>
          <ul>
            <li v-for="(v, k) in jctest.a2">第{{ v[0] + 1 }}题有{{ v[1] }}个</li>
          </ul>
        </li>
        <li v-show="jctest.a3.length">
          <h5>测试点得分不建议是0%</h5>
          <ul>
            <li v-for="(v, k) in jctest.a3">第{{ v[0] + 1 }}题有{{ v[1] }}个测试点为0分</li>
          </ul>
        </li>
        <li v-show="jctest.a4.length">
          <h5>测试点之和建议是100%</h5>
          <ul>
            <li v-for="(v, k) in jctest.a4">第{{ v[0] + 1 }}题有测试点总分不为100分</li>
          </ul>
        </li>
        <li v-show="jctest.a5.length">
          <h5>编程题建议设置为100分（这个只在全部是编程题时检测）</h5>
          <ul>
            <li v-for="(v, k) in jctest.a5">第{{ v[0] + 1 }}题分数不为100分</li>
          </ul>
        </li>
        <li v-show="!jctest.a6">
          <h5>报名结束时间建议在当前时间之后</h5>
          <span>报名结束时间建议在当前时间之后</span>
        </li>
        <li v-show="jctest.a7 > 6">
          <h5>比赛时长建议6小时内</h5>
          <span>比赛时长建议6小时内</span>
        </li>
        <li v-show="jctest.a8.length">
          <h5>检测比赛题目是否有0分题</h5>
          <ul>
            <li v-for="(v, k) in jctest.a8">第{{ v[0] + 1 }}题分数为0分</li>
          </ul>
        </li>
      </ol>
      <div class="row">
        <div class="col text-right">
          <el-button @click="dialogVisible3 = false">取消</el-button>
          <el-button type="success" @click="submit(true)">保存</el-button>
        </div>
      </div>
    </el-dialog>
  </el-form>
</template>
<script setup lang="ts">
import { Close } from '@element-plus/icons-vue';
import dayjs from 'dayjs';
import { ElForm, ElMessage, ElMessageBox, ElUpload } from "element-plus";
import moment from "moment";
import { groupBy } from "underscore";
import {
  computed,
  onMounted,
  reactive,
  ref,
  watch
} from "vue";
import { useRoute, useRouter } from "vue-router";
import vuedraggable from "vuedraggable";
import { useStore } from "vuex";
import User from "../../../admin/views/User/index.vue";
import {
  asyncadminchangematchquestion,
  asyncadmingetactivity,
  asyncadminselectmatchquestion,
  asynccreateorupdateactivity,
  asyncgetquestion,
} from "../../../api/index";
import questionbankinput from "../../../components/questioninput.vue";
import Wangeditor from "../../../components/wangeditor.vue";
import { Storekey } from "../../../interface";
import Studycodemodel from "../../../mysql_interface/studycodemodel";
import updateoss from "../../../util/updateoss";
import { Activity } from "../data";
import { activityrules } from "../data/formrules";
const router = useRouter()
const route = useRoute()
const duration = ref(false)
const dialogVisible3 = ref(false)

const jctest = computed(() => {
  const a1: [number, number][] = []
  const a2: [number, number][] = []
  const a3: [number, number][] = []
  const a4: [number, number][] = []
  const a5: [number, number][] = []
  const lengths = questions.value?.sort((a, b) => Number(a.paixu) - Number(b.paixu)).map((e, k) => {
    return [k, e.type, e.example, e.score];
  }).filter(e => e[1] === '代码') as [number, string, Studycodemodel.Itestcases[], number][]
  if (lengths?.length) {
    lengths.forEach(e => {
      const [k, _type, exa, score] = e
      if (Array.isArray(exa)) {
        a1.push([k, exa.length])
        a2.push([k, exa.length])
        a3.push([k, exa.filter(e => !e.score).length])
        a4.push([k, exa.map(c => c.score).reduce<number>((a = 0, b = 0) => a + b, 0)])
      }
      a5.push([k, score])
    })
  }
  const a6 = ruleForm.type === 'public' ? dayjs(ruleForm.signupendtime).valueOf() > Date.now() : true
  const a7 = moment(ruleForm.activityendtime).diff(moment(ruleForm.activitystarttime), 'hours')
  return {
    a1: a1.filter(e => e[1] < 5),
    a2: a2.filter(e => e[1] > 50),
    a3: a3.filter(e => e[1]),
    a4: a4.filter(e => e[1] !== 100),
    a5: a5.filter(e => e[1] !== 100),
    a6,
    a7,
    a8: a5.filter(e => e[1] === 0)
  }
})

const isshowjctest = computed(() => {
  const n = jctest.value.a1.length + jctest.value.a2.length + jctest.value.a3.length + jctest.value.a4.length + jctest.value.a5.length + jctest.value.a8.length
  return !!n || !jctest.value.a6 || jctest.value.a7 > 6
})


const rules = activityrules;
const ruleForm = reactive(
  Object.assign(
    {
      score: {
        判断: 10,
        单选: 10,
        多选: 10,
      },
    },
    Activity
  )
);

const upload = ref<typeof ElUpload>();
const rule = ref<typeof ElForm>();
const questions = ref<Studycodemodel.Imatchquestion[]>([]);
const dialogVisible = ref(false);
const dialogVisible2 = ref(false);
const title = ref("添加");
const context = ref("");
const htmlcontext = ref("");

const applicationcontext = ref("");
const htmlapplicationcontext = ref("");

const radio = ref(true);
const questionbankid = ref<number | undefined>();
const contexteditor = ref();
const contexteditor2 = ref();
const store = useStore(Storekey);
const selectarr = ref<Studycodemodel.Iuser[]>([]);
const matchquestionbankid = ref();
const users = computed<any>({
  get() {
    return selectarr.value.map((v) => v.name).join(",");
  },
  set(e) { },
});
const startTime = computed<(Date)[]>({
  get() {
    return [dayjs(ruleForm.activitystarttime).toDate(), dayjs(ruleForm.activityendtime).toDate()];
  },
  set([time1, time2]) {
    ruleForm.activitystarttime = time1;
    ruleForm.activityendtime = time2;
  },
});
const signUp = computed<Date[]>({
  get() {
    return [dayjs(ruleForm.signupstarttime).toDate(), dayjs(ruleForm.signupendtime).toDate()];
  },
  set([time1, time2]) {
    ruleForm.signupstarttime = time1;
    ruleForm.signupendtime = time2;
  },
});

watch(
  () => route.query.ID,
  (v) => {
    if (v && typeof v === "number") {
      start();
      dialogVisible.value = true;
    }
  }
);

const getteam = computed(() => {
  return store.state.team?.rows || []
})

const loading = ref(false);

async function remoteMethod(query: any) {
  if (query !== "") {
    const like: any = ["ID", query];
    if (Number(query) != query) {
      like[0] = "name";
    }
    loading.value = true;
    await store.dispatch("actionquestionbank", {
      _like: like,
    });
    loading.value = false;
  }
}

async function remoteMethod1(query: string | number) {
  if (query !== "") {
    const like: any = ["ID", query];
    if (Number(query) != query) {
      like[0] = "name";
    }
    loading.value = true;
    await store.dispatch("actionteam", {
      _like: like,
    });
    loading.value = false;
  }
}

const getquestionbank = computed<Studycodemodel.Iquestionbank[]>(() => {
  return store.getters.getquestionbank;
});

const grouplabel = computed(() => {
  return groupBy<Studycodemodel.ILabel>(
    store.getters.getlabel,
    ({ type }) => type
  );
});

const input3 = ref<number>(10);
const select = ref<Studycodemodel.Iquestion["type"]>("代码");

onMounted(async () => {
  // 初始化
  await start();
  // 是否有团队
});

// 开始
async function start() {
  try {
    if (Number(route.query.ID)) {
      const data = await asyncadmingetactivity({ ID: Number(route.query.ID) })
      Object.assign(ruleForm, data)
    } else {
      Object.assign(ruleForm, Activity);
    }
    duration.value = !!ruleForm.duration

    if (ruleForm.teamid) {
      await store.dispatch("actionteam", {
        ID: ruleForm.teamid
      });
    }
    context.value = ruleForm.context || "";
    htmlcontext.value = ruleForm.htmlcontext || "";
    applicationcontext.value = ruleForm.applicationcontext || "";
    htmlapplicationcontext.value = ruleForm.htmlapplicationcontext || "";
    questions.value = [];
    questionbankid.value = undefined;
    const data = ruleForm.activityuser?.map((v) =>
      v.user ? v.user : { ID: v.userid }
    ) as Studycodemodel.Iuser[];
    if (data) {
      selectarr.value = data;
    } else {
      selectarr.value = [];
    }
    if (ruleForm.ID) {
      asyncadminselectmatchquestion({ activityid: ruleForm.ID })
        .then((v) => {
          if (v) {
            questions.value =
              v.rows.sort(
                (a, b) => Number(a.paixu) - Number(b.paixu)
              ) || [];
          }
        })
        .catch((e) => {
          ElMessage.error(e);
        });
    }
    activeName.value = "first";
  } catch (e: any) {
    ElMessage.error(e);
  }
}

async function request(file: { file: File }) {
  if (upload.value) upload.value.clearFiles();
  const { name } = await updateoss([file.file]);
  ruleForm.banner = `https://cdn.hterobot.com/${name}`;
  // return res;
}

function delquestion(index: number) {
  const x = questions.value[index]
  if (x && x.ID) {
    ElMessageBox.confirm("是否删除该题, 删除后此题关联的用户答题都将被删除?", "提示", {
      confirmButtonText: "确定",
      cancelButtonText: "取消",
      type: "error",
    }).then(async () => {
      try {
        questions.value.splice(index, 1)
      } catch (e: any) {
        ElMessage.error(e);
      }
    });
  } else {
    questions.value.splice(index, 1)
  }

}

function handleSelectionChange(data: Studycodemodel.Iuser[]) {
  selectarr.value = data;
}

function selectquestion(id: Studycodemodel.Iquestion) {
  const t = questions.value.findIndex((v) => v.name === id.name);
  if (t == -1) {
    const { ID = 0 } = id;
    asyncgetquestion({ ID })
      .then((e) => {
        const { testcases, ID, ...data } = e;
        questions.value.push({
          ...data,
          oldid: ID,
          example: testcases,
          score: 100,
        });
      })
      .catch((n) => {
        ElMessage.error("添加失败");
      });
  }
}
function change(value: number, str: Studycodemodel.Iquestion["type"]) {
  questions.value = questions.value.map((v) => {
    let { type } = v;
    if (type === str) {
      v.score = value;
    }
    return {
      ...v,
    };
  });
}

function clearquestion(str: Studycodemodel.Iquestion["type"]) {
  questions.value = questions.value.filter((e) => e.type !== str);
}

function updatetestcase() {
  for (const v of questions.value) {
    v.score = 100
    if (v.type === '代码') {
      const length = v?.example?.length;
      if (length) {
        const score = Math.floor(100 / length);
        const yu = 100 % length;
        v.example = v.example?.map((e, k) => {
          let n = 0;
          if (k > length - yu - 1) {
            n = n + 1;
          }
          return {
            ...e,
            score: score + n,
          };
        });
      }
    }
  }
}

const activeName = ref<"first" | "two">("first");

// 提交
async function submit(t: boolean, next?: boolean) {
  try {
    await ElMessageBox.confirm("是否自动配置题目分值?", "提示", {
      confirmButtonText: "确定",
      cancelButtonText: "取消",
      type: "error",
    })
    updatetestcase()

  } catch (e) {

  }
  try {
    const context = contexteditor.value?.gethtml();
    const htmlcontext = contexteditor.value?.getcontext();
    ruleForm.context = context;
    ruleForm.htmlcontext = htmlcontext;

    ruleForm.applicationcontext = contexteditor2.value?.gethtml();;
    ruleForm.htmlapplicationcontext = contexteditor2.value?.getcontext();;

    if (!t && rule.value) {
      rule.value.validate(async (e: any) => {
        if (e) {
          if (!duration.value) {
            delete ruleForm.duration
          }
          const data = await asynccreateorupdateactivity({
            activity: ruleForm,
            users: selectarr.value.map((v) => v.ID),
            matchquestionbankid: matchquestionbankid.value,
          });
          Object.assign(ruleForm, data);
          if (next) {
            if (data.ID) {
              asyncadminselectmatchquestion({ activityid: data.ID })
                .then((v) => {
                  if (v) {
                    questions.value = v.rows.sort(
                      (a, b) => Number(a.paixu) - Number(b.paixu)
                    ) || [];
                  }
                })
                .catch((e) => {
                  ElMessage.error(e);
                });
            }
            activeName.value = "two";
          } else {
            router.push({
              name: '比赛管理'
            })
          }

          ElMessage({
            message: "添加成功",
            type: "success",
          });
        }
      });
    } else {
      if (ruleForm.ID) {
        await asyncadminchangematchquestion({
          activityid: ruleForm.ID,
          question: questions.value,
        });
      }
      ElMessage({
        message: "添加成功",
        type: "success",
      });
      router.push({
        name: '比赛管理'
      })
    }
  } catch (e: any) {
    ElMessage({
      message: e,
      type: "error",
    });
  }
}
</script>

<style scoped>
.demo-ruleForm {
  padding-bottom: 10px;
  background-color: #fff;
  min-height: 100%;
}

.row10 {
  height: 130px;
}

.el-icon-remove {
  cursor: pointer;
}

.width300 {
  width: 300px;
}

.item {
  margin-left: 20px;
}

.list-group {
  height: 700px;
  overflow: auto;
}
</style>

<style>
.row10 textarea {
  height: 130px;
}

.input-with-select .el-select .el-input {
  width: 80px;
}
</style>